package ai.people.netmon.facebook.monitor.controller;

import ai.people.core.standard.analysis.entity.request.JoinAnalysisRequest;
import ai.people.netmon.facebook.monitor.service.FacebookMonitorUsersService;
import ai.people.netmon.framework.domain.common.monitor.MonitorUsersListVO;
import ai.people.netmon.framework.domain.common.monitor.MonitorUsersVO;
import ai.people.netmon.framework.domain.facebook.monitor.request.MonitorUsersRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 监测-facebook-users查询接口
 *
 * @author zhenglin
 * @since 2022/3/8
 */
@RestController
@RequestMapping("/monitor/user/")
public class FacebookMonitorUsersController {

    @Autowired
    FacebookMonitorUsersService facebookMonitorUsersService;

    /**
     * 获取用户信息
     *
     * @param userName 用户名
     * @return {@link Result}<{@link MonitorUsersVO}>
     */
    @GetMapping("/{userName}")
    Result<MonitorUsersVO> getUserInfo(@PathVariable("userName") String userName){
        MonitorUsersVO monitorUsers = facebookMonitorUsersService.getUsers(userName);
        return ResultUtil.success(monitorUsers);
    }

    /**
     * 分页获取用户信息列表
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link MonitorUsersListVO}>>
     */
    @PostMapping("/list")
    Result<PageResponse<MonitorUsersListVO>> listUserInfo(@RequestBody MonitorUsersRequest request){
        PageResponse<MonitorUsersListVO> response = facebookMonitorUsersService.listUserInfo(request);
        return ResultUtil.success(response);
    }

    /**
     * 加入分析
     *
     * @param request 请求
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/addAnalysis")
    Result<Boolean> addAnalysis(@Valid @RequestBody JoinAnalysisRequest request){
        facebookMonitorUsersService.addAnalysis(request);
        return ResultUtil.success();
    }

}
